<?php


namespace App\Api\Models;

use Illuminate\Database\Eloquent\Model;

class CmcUserSeckill extends Model
{
    protected $table='cmc_user_seckills';

    //添加商品秒杀商品入库
    static public function addSeckill($data)
    {
        return CmcUserSeckill::insert($data);
    }

    //修改用户订单状态
    static public function upStatus($id,$status)
    {
        return CmcUserSeckill::where('id',$id)->update(['status'=>$status]);
    }

    public static function getStoreSeckill()
    {
        return self::select('seckill_id')->get()->toArray();
    }

    public static function getYearStoreSeckill($sec_id)
    {
        $time = date('Y-m-d',time()-86400);

        $data = Seckill::where('id',$sec_id)->get()->toArray();

        $count = count($data);

        for($i=0;$i<$count;$i++){
            $data[$i]['created_at'] = strtotime(str_replace('T',' ',$data[$i]['created_at']));
        }

        $all = [];

        for($j=0;$j<$count;$j++){
            if($data[$j]['created_at'] <$time && $data[$j]['created_at']<$time+86400){
                unset($data[$j]);
            }else{
                $all[$j] = [$data[$j]['goods_id'],$data[$j]['goods_name'],$data[$j]['created_at']];
            }
        }

        return $all;
    }

    static public function secInGoods($sec_id,$where)
    {
        $secGoodsId = Seckill::where('id',$sec_id)->get([$where])->toArray();

        $arr = [];

        $count = count($secGoodsId);

        for($i=0;$i<$count;$i++){

            $arr = Goods::where('goods_id',$secGoodsId[$i]['goods_id'])->select('goods_id','goods_name','goods_image','created_at')->get()->toArray();

        }

        return $arr;
    }
}